""" Media wiki highlighter for terminal

"""

import lexer

class colors():
	none = "\033[0m"
	bold = "\033[1m"
	underline = "\033[4m"
	red = "\033[91m"
	green = "\033[92m"
	blue = "\033[94m"
	gray = "\033[90m"
	white = "\033[97m"
	yellow = "\033[93m"

toccol = { 
	lexer.COMMENT:colors.gray, 
	lexer.TEXT: colors.white,
	lexer.MARKUP: colors.red,
	lexer.IGNORED: colors.green,
	lexer.LINK: colors.underline+colors.blue,
	lexer.HEADER: colors.blue,
	lexer.INTERWIKI: colors.yellow
}

def print_highlighted(tokens):
	text = []
	for i in tokens:
			text.append(toccol[i[0]])
			text.append(lexer.token_text(i))
			text.append(colors.none)
	print "".join(text)

if __name__=="__main__":
	from page import text
	lex,rest = lexer.parser(text)
	print_highlighted(lex)
	if len(rest)>0:
		print "Warning: some part of text don't parsed"
		print "REST:", rest[:100],"..."
